package jbox2dprocessing.compontent;

import org.jbox2d.common.Vec2;

import fisica.FBox;

import processing.core.PApplet;
import processing.core.PConstants;

public class BaseBox extends AbstractBox2DShape{
	
	public FBox baseBox;
	
	//	BaseBox Shape
	public float baseWidth;
	public float baseHeight;
	
	//	Define Basic BaseBox
	public BaseBox(int _master){
		super();
		this.baseWidth = 40.0f;
		this.baseHeight = 15.0f;
		this.master = _master;
		makeBaseBody(baseWidth, baseHeight, new Vec2(baseX, baseY));
	}
	
	public BaseBox(int _master, float baseDensity){
		super( baseDensity);
		this.baseWidth = 40.0f;
		this.baseHeight = 15.0f;
		this.master = _master;
		makeBaseBody(baseWidth, baseHeight, new Vec2(baseX, baseY));
	}
	
	//	Define costumized BaseBox
	public BaseBox(float baseX, float baseY, float baseWidth,
			float baseHeight, int _master, float baseDensity, float baseFriction,
			float baseRestitution) {
		super(baseX, baseY, baseDensity, baseFriction, baseRestitution);
		this.baseWidth = baseWidth;
		this.baseHeight = baseHeight;
		this.master = _master;
		makeBaseBody(baseWidth, baseHeight, new Vec2(baseX, baseY));
	}
	
	
	public BaseBox(float baseX, float baseY, float baseWidth,
			float baseHeight, int _master, int baseColor, int baseStrokeColor,
			int baseStrokeWeight, float baseDensity, float baseFriction,
			float baseRestitution) {
		super(baseX, baseY, baseColor, baseStrokeColor, baseStrokeWeight, baseDensity, baseFriction, baseRestitution);
		this.baseWidth = baseWidth;
		this.baseHeight = baseHeight;
		this.master = _master;
		makeBaseBody(baseWidth, baseHeight, new Vec2(baseX, baseY));
	}
	
	public void makeBaseBody(float _w, float _h, Vec2 center){
//		PolygonDef sd = new PolygonDef();
//		float box2dW = box2d.scaleScreenToWorld(_w/2);
//		float box2dH = box2d.scaleScreenToWorld(_h/2);
//		sd.setAsBox(box2dW, box2dH);
//		
//		sd.density = baseDensity;
//		sd.friction = baseFriction;
//		sd.restitution = baseRestitution;
//		
//		BodyDef bd = new BodyDef(this.master);
//		bd.position.set(box2d.screenToWorld(center));
//		
//		baseBody = box2d.createBody(bd);
//		baseBody.createShape(sd);
//		baseBody.setMassFromShapes();
		baseBox = new FBox(baseWidth, baseHeight);
		baseBox.setDensity(baseDensity);
		baseBox.setFriction(baseFriction);
		baseBox.setRestitution(baseRestitution);
		baseBox.setPosition(center.x, center.y);
		
		baseBox.setFillColor(baseColor);
		baseBox.setStrokeWeight(baseStrokeWeight);
		baseBox.setStrokeColor(baseStrokeColor);
		
//		baseBox.setGrabbable(false);
		
		baseBox.addToWorld(world, master);
	}
	
//	public void display(){
//		Vec2 pos = box2d.getScreenPos(baseBody);
//		float a = baseBody.getAngle();
//		
//		parent.rectMode(PConstants.CENTER);
//		parent.pushMatrix();
//		parent.translate(pos.x, pos.y);
//		parent.rotate(PConstants.PI - a);
//		parent.fill(baseColor);
//		parent.stroke(baseStrokeColor);
//		parent.strokeWeight(baseStrokeWeight);
//		parent.rect(0, 0, baseWidth, baseHeight);
//		parent.popMatrix();
//	}
	public float getPosX(){
		return baseBox.getX();
	}
	
	public float getPosY(){
		return baseBox.getY();
	}
	
	public float getAngle(){
		return baseBox.getRotation();
	}

}
